#include<bits/stdc++.h>
using namespace std;
class Solution1
{
public:
    vector<string> uncommonFromSentences(string s1, string s2)
    {
        unordered_map<string, int> m;
        stringstream ss;
        ss << s1 << " " << s2;
        string s;
        while (ss >> s)
            ++m[move(s)];
        vector<string> ans;
        for (auto &&[s, c] : m)
            if (c == 1)
                ans.emplace_back(move(s));
        return ans;
    }
};
class Solution
{
public:
    vector<string> uncommonFromSentences(string s1, string s2)
    {
        unordered_map<string, int> map1, map2;
        int index1 = 0, index2 = 0;
        int begin1, begin2, end1, end2;
        while (index1 < s1.size() || index2 < s2.size())
        {
            begin1 = index1;
            begin2 = index2;
            end1 = index1;
            end2 = index2;
            while (index1 < s1.size() && s1[index1] != ' ')
            {
                index1++;
                end1++;
            }
            if (index1 <= s1.size())
                map1[s1.substr(begin1, end1 - begin1)]++;
            index1++;
            end1++;
            while (index2 < s2.size() && s2[index2] != ' ')
            {
                index2++;
                end2++;
            }
            if (index2 <= s2.size())
                map2[s2.substr(begin2, end2 - begin2)]++;
            index2++;
            end2++;
        }
        vector<string> ret;
        for (const auto &val : map1)
        {
            if (val.second == 1 && map2.count(val.first) == 0)
            {
                ret.emplace_back(val.first);
            }
        }
        for (const auto &val : map2)
        {
            if (val.second == 1 && map1.count(val.first) == 0)
            {
                ret.emplace_back(val.first);
            }
        }
        return ret;
    }
};
int main()
{
    Solution().uncommonFromSentences("apple apple", "banana");
    return 0;
}